package com.itheima;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.config.SpringConfig;
import com.itheima.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        /*ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.back.xml");

        UserService userService = (UserService) ctx.getBean("userService");
        userService.save();

        // UserDao userDao = (UserDao) ctx.getBean("userDao");
        // userDao.save();
        // BookDao bookDao = (BookDao) ctx.getBean("bookDao");
        // bookDao.save();

        // DataSource dataSource = new DruidDataSource();
        // System.out.println("dataSource = " + dataSource);
        DruidDataSource ds = ctx.getBean("dataSource", DruidDataSource.class);
        System.out.println("ds = " + ds);

        ctx.close();  // JVM关闭前执行destroy销毁方法*/

        ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = ctx.getBean("userService", UserService.class);
        userService.save();

    }
}
